import 'package:capsule/widgets/dialog/dialog_template.dart';

import 'package:flutter/material.dart';

class AddFileToDBDialog extends StatefulWidget {
  final void Function(String shelf)? onOk;
  final void Function()? onCancel;
  const AddFileToDBDialog({super.key, this.onOk, this.onCancel});

  @override
  State<AddFileToDBDialog> createState() => _AddFileToDBDialogState();
}

class _AddFileToDBDialogState extends State<AddFileToDBDialog> {
  late final TextEditingController _shelfController;
  final GlobalKey<FormState> _formKey = GlobalKey();
  @override
  void initState() {
    super.initState();

    _shelfController = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    double dlgWidth = 560;
    return DialogTemplate(
      onCancel: widget.onCancel,
      onOk: () {
        if (_formKey.currentState!.validate() == false) return;

        widget.onOk?.call(_shelfController.value.text);
      },
      child: Column(
        children: [
          const Text("请输入位置："),
          Form(
            key: _formKey,
            child: SizedBox(
              width: dlgWidth - 40,
              child: TextFormField(
                controller: _shelfController,
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return "不能为空";
                  }
                  return null;
                },
              ),
            ),
          )
        ],
      ),
    );
  }
}
